package com.ohos.carbon.slice;

import com.ohos.carbon.LogUtils;
import com.ohos.carbon.ResourceTable;
import com.ohos.carbon.model.DataBean;
import com.ohos.carbon.slice.animations.ImageFadeSlice;
import com.ohos.carbon.slice.animations.PathAnimationSlice;
import com.ohos.carbon.slice.animations.TouchRippleSlice;
import com.ohos.carbon.slice.animations.WidgetAnimationsSlice;
import com.ohos.carbon.slice.componentList.*;
import com.ohos.carbon.slice.demos.*;
import com.ohos.carbon.slice.dialog.*;
import com.ohos.carbon.slice.guidelines.*;
import com.ohos.carbon.slice.libraries.ConstraintLayoutSlice;
import com.ohos.carbon.slice.libraries.PicassoSlice;
import com.ohos.carbon.slice.themes.CurrentThemeSlice;
import com.ohos.carbon.slice.themes.DarkAndLightSlice;
import com.ohos.carbon.slice.themes.WindowsThemesSlice;
import com.ohos.carbon.slice.widgets.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.ListContainer;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ElementScatter;

import java.util.ArrayList;
import java.util.Map;

import static com.ohos.carbon.slice.MainAbilitySlice.preferences;

public class FavouritesSlice extends AbilitySlice {

    Map<String, Boolean> allPreferences;

    private ArrayList<DataBean> mList;
    private ListContainer listContainer;
    private Element favour;

    private Image back_button;
    private Text text_title, text;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_favourites);
        initData();
        initView();
    }

    private void initView() {
        back_button = (Image) findComponentById(ResourceTable.Id_back_button);
        text_title = (Text) findComponentById(ResourceTable.Id_title_text);
        text_title.setText("Favourites");
        listContainer = (ListContainer) findComponentById(ResourceTable.Id_listview);
        back_button.setImageElement(ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_carbon_uparrow));
        listContainer.setItemProvider(new WhatsProvider(mList,getContext()));

        //返回上个页面
        back_button.setClickedListener(component -> {
            onBackPressed();
        });

        listContainer.setItemClickedListener(new ListContainer.ItemClickedListener() {
            @Override
            public void onItemClicked(ListContainer listContainer, Component component, int i, long l) {

                LogUtils.d("Darren"," Click Text:" + mList.get(i).getText());
                Intent intent = new Intent();
                if (mList.get(i).getText().equals("Widget animations")){
                    present(new WidgetAnimationsSlice(),intent);
                }else if (mList.get(i).getText().equals("Image fade")){
                    present(new ImageFadeSlice(),intent);
                }else if(mList.get(i).getText().equals("Touch ripple")){
                    present(new TouchRippleSlice(),intent);
                }else if (mList.get(i).getText().equals("Path animation")){
                    present(new PathAnimationSlice(),intent);
                }else if (mList.get(i).getText().equals("Icon and text list item")){
                    present(new IconAndTextSlice(),intent);
                }else if (mList.get(i).getText().equals("Avatar and text list item")){
                    present(new AvatarAndTextSlice(),intent);
                }else if (mList.get(i).getText().equals("Image,text,subtext and date list item")){
                    present(new ImageAndTextSlice(),intent);
                }else if (mList.get(i).getText().equals("Avatar,text,rating,subtext and date list item")){
                    present(new RatingAndTextSlice(),intent);
                }else if (mList.get(i).getText().equals("Registration form")){
                    present(new RegistrationFromSlice(),intent);
                }else if (mList.get(i).getText().equals("ComponentView")){
                    present(new ComponentViewSlice(),intent);
                }else if (mList.get(i).getText().equals("Power Menu")){
                    present(new PowerMenuSlice(),intent);
                }else if (mList.get(i).getText().equals("Auto Complete")){
                    present(new AutoCompleteSlice(), intent);
                }else if (mList.get(i).getText().equals("Quick Return")){
                    present(new QuickReturnSlice(), intent);
                }else if (mList.get(i).getText().equals("Search Toolbar")){
                    present(new SearchToolbarSlice(), intent);
                }else if (mList.get(i).getText().equals("Share toolbar")){
                    present(new ShareToolbarSlice(), intent);
                }else if (mList.get(i).getText().equals("Profile")){
                    present(new ProfileSlice(), intent);
                }else if (mList.get(i).getText().equals("Music player")){
                    present(new MusicplayerSlice(), intent);
                }else if (mList.get(i).getText().equals("Collapsing toolbar")){
                    present(new CollapsingtoolbarSlice(), intent);
                }else if (mList.get(i).getText().equals("Banner")){
                    present(new BannerSlice(), intent);
                }else if (mList.get(i).getText().equals("CheckBoxes & RadioButtons")){
                    present(new CheckBoxesSlice(), intent);
                }else if (mList.get(i).getText().equals("Buttons")){
                    present(new ButtonsSlice(), intent);
                }else if (mList.get(i).getText().equals("Floating Action Button")){
                    present(new FloatingSlice(), intent);
                }else if (mList.get(i).getText().equals("Circular progress")){
                    present(new CircularSlice(), intent);
                }else if (mList.get(i).getText().equals("Menus")){
                    present(new MenusSlice(), intent);
                }else if (mList.get(i).getText().equals("Progress bars")){
                    present(new ProgressSlice(), intent);
                }else if (mList.get(i).getText().equals("Snackbar")){
                    present(new SnackbarSlice(), intent);
                }else if (mList.get(i).getText().equals("Text fields")){
                    present(new Text_filedsSlice(), intent);
                }else if (mList.get(i).getText().equals("Tabs")){
                    present(new TabsSlice(), intent);
                }else if (mList.get(i).getText().equals("RecyclerView")){
                    present(new RecyclerViewSlice(), intent);
                }else if (mList.get(i).getText().equals("ExpandableRecyclerView")){
                    present(new ExpandableRecyclerViewSlice(), intent);
                }else if (mList.get(i).getText().equals("ExpansionPanel")){
                    present(new ExpansionPanelSlice(), intent);
                }else if (mList.get(i).getText().equals("DropDown")){
                    present(new DropDownSlice(), intent);
                }else if (mList.get(i).getText().equals("NavigationView")){
                    present(new NavigationViewSlice(), intent);
                }else if (mList.get(i).getText().equals("SeekBar")){
                    present(new SeekBarSlice(), intent);
                }else if (mList.get(i).getText().equals("FlowLayout & Chips")){
                    present(new FolwLayoutSlice(), intent);
                }else if (mList.get(i).getText().equals("TableLayout")){
                    present(new TableLayoutSlice(), intent);
                }else if (mList.get(i).getText().equals("BottomNavigationView")){
                    present(new BottomNavigationSlice(), intent);
                }else if (mList.get(i).getText().equals("BottomSheet")){
                    present(new BottomSheetSlice(), intent);
                }else if (mList.get(i).getText().equals("Backdrop")){
                    present(new BackdropSlice(), intent);
                }else if (mList.get(i).getText().equals("Bar chart")){
                    present(new HistogramViewDemo(), intent);
                }else if (mList.get(i).getText().equals("Line chart")){
                    present(new ChartViewDemo(),intent);
                }else if (mList.get(i).getText().equals("Gesture detectot")){
                    present(new GesturedetectorSlice(), intent);
                }else if (mList.get(i).getText().equals("Auto size text")){
                    present(new AutoSizeTextSlice(), intent);
                }else if (mList.get(i).getText().equals("Behavior")){
                    present(new BehaviorSlice(), intent);
                }else if (mList.get(i).getText().equals("HTML")){
                    present(new HtmlSlice(), intent);
                }else if (mList.get(i).getText().equals("XML Font")){
                    present(new XmlFontSlice(), intent);
                }else if (mList.get(i).getText().equals("Shadow")){
                    present(new ShadowSlice(), intent);
                }else if (mList.get(i).getText().equals("Pagination")){
                    present(new PaginationSlice(), intent);
                }else if (mList.get(i).getText().equals("Text appearance")){
                    present(new TextAppearanceSlice(), intent);
                }else if (mList.get(i).getText().equals("SVG icons")){
                    present(new SVGiconsSlice(), intent);
                }else if (mList.get(i).getText().equals("Z order")){
                    present(new ZOrderSlice(), intent);
                }else if (mList.get(i).getText().equals("Rounded corners")){
                    present(new RoundedSlice(), intent);
                }else if (mList.get(i).getText().equals("Anchors")){
                    present(new AnchorsSlice(), intent);
                }else if (mList.get(i).getText().equals("Text marker")){
                    present(new TextMarkerSlice(), intent);
                }else if (mList.get(i).getText().equals("Button/Usage")){
                    present(new ButtonsUsageActivity(), intent);
                }else if (mList.get(i).getText().equals("Menus/Behavior")){
                    present(new MenusBehaviorActivity(), intent);
                }else if (mList.get(i).getText().equals("Studies/Shrine")){
                    present(new ShrineActivity(), intent);
                }else if (mList.get(i).getText().equals("Studies/Carane")){
                    present(new CraneActivity(), intent);
                }else if (mList.get(i).getText().equals("Studies/Basil")){
                    present(new BasilActivity(), intent);
                }else if (mList.get(i).getText().equals("Picasso")){
                    present(new PicassoSlice(), intent);
                }else if (mList.get(i).getText().equals("ConstraintLayout")){
                    present(new ConstraintLayoutSlice(), intent);
                }else if (mList.get(i).getText().equals("Dark and Light")){
                    present(new DarkAndLightSlice(), intent);
                }else if (mList.get(i).getText().equals("Current Theme")){
                    present(new CurrentThemeSlice(), intent);
                }else if (mList.get(i).getText().equals("Windows Theme")){
                    present(new WindowsThemesSlice(), intent);
                }else if (mList.get(i).getText().equals("List dialog")){
                    present(new ListDialogActivity(), intent);
                }else if (mList.get(i).getText().equals("Progress dialog")){
                    present(new ProgressDialogActivity(), intent);
                }else if (mList.get(i).getText().equals("Select dialog")){
                    present(new SelectDialogActivity(), intent);
                }else if (mList.get(i).getText().equals("Simple dialog")){
                    present(new SimpleDialogActivity(), intent);
                }else if (mList.get(i).getText().equals("Dialog fragment")){
                    present(new DialogFragmentActivity(), intent);
                }
            }
        });
    }

    private void initData() {
        mList = new ArrayList<>();
        Element favour = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_star_gray_24dp);
        allPreferences = (Map<String, Boolean>) preferences.getAll();
        mList.add(new DataBean(null,"Tap the star iconId next to a sample to add it to this list",null,null));
        for (Map.Entry<String, Boolean> entry : allPreferences.entrySet()) {
            LogUtils.d("Darren",entry.getKey());
            LogUtils.d("Darren","" +entry.getValue());
            if (entry.getValue() == true){
                mList.add(new DataBean(null,entry.getKey(),null,favour));
            }
        }

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
